package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.product.CartInfo;
import com.atguigu.spzx.model.vo.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("api/order/cart")
public class CastController {


    @Autowired
    CartService cartService;

    @GetMapping("auth/getAllChecked")
    public List<CartInfo> getAllChecked(){
        //我们需要的是checked的购物车项,但是这里查询的是所有的,
        List<CartInfo> checkedCartList= cartService.getAllChecked();

        return checkedCartList;
    }


    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable Long skuId,@PathVariable Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok(null);
    }

    @GetMapping("/auth/cartList")
    public Result<List<CartInfo>> getCartList(){
        List<CartInfo> cartInfoList = cartService.getCartList();
        return Result.ok(cartInfoList);
    }

    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCartBySkuId(@PathVariable Long skuId){
        cartService.deleteCartBySkuId(skuId);
        return Result.ok(null);
    }


    @GetMapping("/auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable Long skuId,@PathVariable Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.ok(null);
    }

    @GetMapping("/auth/deleteCheckedCart")
    public Result deleteCheckedCart(){
        cartService.deleteCheckedCart();
        return Result.ok(null);
    }
}
